package com.sjq.common.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Repository;

import com.sjq.common.dao.DictTreeDao;
import com.sjq.common.dao.GenericDao;
import com.sjq.common.entity.DictTree;
import com.sjq.common.exception.DataAccessException;

@Repository("DictDao")
public class DictTreeDaoImpl extends GenericDao<DictTree> implements DictTreeDao {

	//按照字典类别查询
	@Override
	public List<Map<String, Object>> getAllDictByCategory(String category) {
		//ConnDb db=new ConnDb();
		//select org_name,org_code,parent_code,dictionary_name,full_name,org_shortname as  from t_sys_jgdw_dwxx t where org_type='10' and org_status='2000' and parent_code=? order by ordercode asc
		String sql = "select org_code as DWBM,org_shortname as  DWMC,parent_code as SJBMDM from T_SYS_JGDW_DWXX where  org_type='10' and org_status='2000' and  org_code!='321300000000' order by ordercode";
		Object[] param = { category };
		List<Map<String, Object>> dictList =this.getJdbcTemplate().queryForList(sql);
		return dictList;
	}

	//按照字典类别和父代码查询
	@Override
	public DictTree selectSingleDictTree(String category, String pid)
			throws DataAccessException {
		String sql = "select DWBM,DWMC,SJBMDM from t_sys_dw_gajg where dwbm!='321300000000' and SJBMDM = ? order by dwbm";
		DictTree jsTree = new DictTree();
		SqlRowSet rs = this.getJdbcTemplate().queryForRowSet(sql,
				new Object[] { pid });
		while (rs.next()) {
			jsTree.setId(rs.getString("zddm"));
			jsTree.setName(rs.getString("zdmc"));
			jsTree.setPid(rs.getString("fzddm"));
			jsTree.setOrderno(rs.getInt("orderno"));
		}

		return jsTree;
	}

	//单位树
	@Override
	public List<Map<String, Object>> getDwTree() {
		//ConnDb db=new ConnDb();
		
		String sql = "select DWBM,DWMC,SJBMDM from t_sys_dw_gajg where dwbm!='321300000000' order by dwbm";
		List<Map<String, Object>> dictList =this.getJdbcTemplate().queryForList(sql);
		return dictList;

	}

}
